import time

from common.base import Base

register_url = 'http://ecshop.itsoso.cn/user.php'


class RegisterPage(Base):
    """注册页面表现层,制作定位器"""
    username_loc = ("id", "username")  # 用户名
    email_loc = ("id", "email")  # 邮箱
    password_loc = ("id", "password1")  # 密码
    re_password_loc = ("id", "conform_password")  # 确认密码
    # qq_loc = ("name", "extend_field2")
    tel_phone_loc = ("name", "extend_field5")  # 电话
    question_loc = ("name", "sel_question")  # 密码问题
    answer_loc = ("name", "passwd_answer")  # 问题回答
    checkbox_loc = ("name", "agreement")  # 已阅读选择框
    register_loc = ("name", "Submit")  # 立即注册
    agreement_loc = ("link text", "用户协议")  # 用户协议内容跳转
    login_loc = ("link text", "我已有账号，我要登录")  # 登录
    find_password_loc = ("link text", "您忘记密码了吗？")  # 找回密码
    home_page_loc = ("link text", "首页")  # 首页
    click_register_loc = ("link text", "免费注册")

    def home_click_register(self):
        """跳转到立即注册"""
        self.click(self.click_register_loc)
        time.sleep(5)

    def input_username(self, username):
        """输入用户名"""
        self.send_keys(self.username_loc, username)
        time.sleep(1)

    def input_email(self, email):
        self.send_keys(self.email_loc, email)
        time.sleep(1)

    def input_password(self, password):
        """输入密码"""
        self.send_keys(self.password_loc, password)
        time.sleep(1)

    def input_repassword(self, repassword):
        """输入确认密码"""
        self.send_keys(self.re_password_loc, repassword)
        time.sleep(1)

    def input_tel(self, tel):
        """输入手机号"""
        self.send_keys(self.tel_phone_loc, tel)
        time.sleep(1)

    def check_password_question(self, question):
        """选择密码问题"""
        self.select_by_index(self.question_loc, question)
        time.sleep(1)

    def answer(self, answer):
        """输入问题答案"""
        self.send_keys(self.answer_loc, answer)
        time.sleep(1)

    def select_agreement(self):
        """勾选已看过协议"""
        self.radio(self.checkbox_loc)
        time.sleep(1)

    def click_register(self):
        """点击立即注册"""
        self.click(self.register_loc)
        time.sleep(3)

    def click_login(self):
        """点击登录"""
        self.click(self.login_loc)
        time.sleep(3)

    def click_agreement(self):
        """点击用户协议"""
        self.click(self.agreement_loc)
        time.sleep(3)

    def click_find_password(self):
        """点击找回密码"""
        self.click(self.find_password_loc)
        time.sleep(3)

    def click_home_page(self):
        """点击首页"""
        self.click(self.home_page_loc)
        time.sleep(3)
